/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package has.game;

import EJB_GameLogic.GameLogicRemote;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.naming.InitialContext;

/**
 *
 * @author DROWNE
 */
@WebService()
public class GameServices {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Register")
    public Integer Register(@WebParam(name = "username")
    String username, @WebParam(name = "password")
    String password, @WebParam(name = "nickname")
    String nickname, @WebParam(name = "email")
    String email) throws Exception {

        InitialContext ic = new InitialContext();
        GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
        return gameLogicInterface.registerUser(username, password, nickname, email);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Login")
    public int Login(@WebParam(name = "username")
    String username, @WebParam(name = "password")
    String password) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.loginUser(username, password);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "CreateNewGame")
    public int createNewGame(@WebParam(name = "owner")
    String owner, @WebParam(name = "duration")
    int duration) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.createNewgame(owner, duration);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetAvailableGames")
    public String GetAvailableGames() throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getAvailableGames();


    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "JoinGame")
    public int JoinGame(@WebParam(name = "username")
    String username, @WebParam(name = "idgame")
    int idgame) throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.joinGame(idgame, username);


    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetPlayersList")
    public String GetPlayersList(@WebParam(name = "idgame")
    int idgame) throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getPlaterList(idgame);

    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "SetPosition")
    public Integer SetPosition(@WebParam(name = "gameSessionID")
    int gameSessionID, @WebParam(name = "latitude")
    int latitude, @WebParam(name = "longitude")
    int longitude) throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.setPosition(gameSessionID, latitude, longitude);

    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "SetCenterPosition")
    public Integer SetCenterPosition(@WebParam(name = "idgame")
    int idgame, @WebParam(name = "centerlat")
    int centerlat, @WebParam(name = "centerlon")
    int centerlon) throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.setCenterPosition(idgame, centerlat, centerlon);

    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetCenterPosition")
    public String GetCenterPosition(@WebParam(name = "idgame")
    int idgame) throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getCenterPosition(idgame);
       
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetGamePhase")
    public Integer GetGamePhase(@WebParam(name = "idgame")
    int idgame) throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getGamePhase(idgame);

    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "SetGamePhase")
    public Integer SetGamePhase(@WebParam(name = "idgame")
    int idgame, @WebParam(name = "gamePhase")
    int gamePhase) throws Exception {

       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.setGamePhase(idgame, gamePhase);

    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "RetrievePlayerPosition")
    public String RetrievePlayerPosition(@WebParam(name = "username")
    String username, @WebParam(name = "idgame")
    int idgame) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.retrievePlayerPosition(username, idgame);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "RetrievePlayerPositionByGameSession")
    public String retrievePlayerPositionByGameSession(@WebParam(name = "gamesessionID")
    int gamesessionID) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.retrievePlayerPositionByGameSession(gamesessionID);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "RetrieveAllPlayerPosition")
    public String retrieveAllPlayerPosition(@WebParam(name = "idgame")
    int idgame) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.retrieveAllPlayerPosition(idgame);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetNumPlayers")
    public Integer GetNumPlayers(@WebParam(name = "idgame")
    int idgame) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getNumPlayers(idgame);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "AssignTeam")
    public Integer SetTeam(@WebParam(name = "gamesessionID")
    int gamesessionID, @WebParam(name = "teamID")
    int teamID) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.assignTeam(gamesessionID, teamID);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetTeam")
    public Integer GetTeam(@WebParam(name = "gamesessionID")
    int gamesessionID) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getTeam(gamesessionID);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "AutoAssignTeams")
    public Integer AutoAssignTeams(@WebParam(name = "idgame")
    int idgame) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.autoAssignTeams(idgame);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetPlayerState")
    public Integer GetPlayerState(@WebParam(name = "gamesessionID")
    int gamesessionID) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getPlayerState(gamesessionID);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "SetPlayerState")
    public Integer SetPlayerState(@WebParam(name = "gamesessionID")
    int gamesessionID, @WebParam(name = "state")
    int state) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.setPlayerState(gamesessionID, state);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "RetrieveTeamMatesPositions")
    public String RetrieveTeamMatesPositions(@WebParam(name = "idgame")
    int idgame, @WebParam(name = "gamesessionID")
    int gamesessionID, @WebParam(name = "team")
    int team) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.retrieveTeamMatesPositions(idgame, gamesessionID, team);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "CalculateDistance")
    public Double CalculateDistance(@WebParam(name = "latVal1")
    String latVal1, @WebParam(name = "lonVal1")
    String lonVal1, @WebParam(name = "latVal2")
    String latVal2, @WebParam(name = "lonVal2")
    String lonVal2) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.calculateDistance(latVal1, lonVal1, latVal2, lonVal2);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetSimplePlayerState")
    public Integer GetSimplePlayerState(@WebParam(name = "gamesessionID")
    int gamesessionID) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getSimplePlayerState(gamesessionID);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "GetCaptureState")
    public Integer GetCaptureState(@WebParam(name = "gamesessionID")
    int gamesessionID) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.getCaptureState(gamesessionID);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "SetCaptureState")
    public Integer SetCaptureState(@WebParam(name = "gamesessionID")
    int gamesessionID, @WebParam(name = "state")
    int state) throws Exception {
       InitialContext ic = new InitialContext();
       GameLogicRemote gameLogicInterface=(GameLogicRemote)ic.lookup("EJB_GameLogic.GameLogicRemote");
       return gameLogicInterface.setCaptureState(gamesessionID, state);
    }


}
